package com.rock.code.bigdata.bigdatainterface.service;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时建周表  年表
 */
public class WeekAndYearTabTask implements Job {
    private static final String exec_tabname_week = "TB_KPI_VALUE_WEEK_";
    private static final String exec_tabname_year = "TB_KPI_VALUE_YEAR_";

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy");

    Logger logger = Logger.getLogger("schedule");

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        CreateTabService createTabService = (CreateTabService) jobExecutionContext.getMergedJobDataMap().get("createTabService");
        Date today = new Date();
        String weekTabName = exec_tabname_week + sdf.format(today);
        String yearTabName = exec_tabname_year + sdf.format(today);
        if (createTabService.isExists(weekTabName)) {
            createTabService.createWeekTab(weekTabName);
        } else {
            logger.info(weekTabName + "已创建");
        }
        if (createTabService.isExists(yearTabName)) {
            createTabService.createYearTab(yearTabName);
        } else {
            logger.info(yearTabName + "已创建");
        }
        try {
            logger.info("job start time: " + new Date());

        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }
}
